package com.alibaba.system.controller;


import com.alibaba.basic.util.AjaxResult;
import com.alibaba.basic.util.PageList;
import com.alibaba.system.domain.Systemdictionarytype;
import com.alibaba.system.query.SystemdictionarytypeQuery;
import com.alibaba.system.service.ISystemdictionarydetailService;
import com.alibaba.system.service.ISystemdictionarytypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarytype")
@Api(tags = "部门接口",description = "部门接口详细描述")
public class SystemdictionarytypeController {

    @Autowired
    private ISystemdictionarytypeService systemdictionarytypeService;

    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailService;

    @GetMapping("/{id}")
    @ApiOperation(value = "查询单条数据",notes = "查询单挑数据操作")
    public Systemdictionarytype findOne(@PathVariable("id") Long id ){
        return systemdictionarytypeService.findById(id);
    }

    @GetMapping
    @ApiOperation(value = "查询所有数据",notes = "查询所有操作")
    public List<Systemdictionarytype> findAll(){
        return systemdictionarytypeService.findAll();
    }

    @PostMapping
    @ApiOperation(value = "分页查询",notes = "分页查询操作")
    public PageList<Systemdictionarytype> pageQuery(@RequestBody SystemdictionarytypeQuery query){
        return systemdictionarytypeService.queryPage(query);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "部门删除",notes = "部门删除操作")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {

                    systemdictionarytypeService.del(id);

                    systemdictionarytypeService.delete(id);

            return new AjaxResult();
        } catch (Exception a){
            a.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }

    @PutMapping
    @ApiOperation(value = "部门添加或修改",notes = "如果有id就是修改否则就是添加")
    public AjaxResult save(@RequestBody Systemdictionarytype systemdictionarytype){
        try {
            if(systemdictionarytype.getId()!=null){
                systemdictionarytypeService.update(systemdictionarytype);
            } else {
                systemdictionarytypeService.add(systemdictionarytype);
            }
            return new AjaxResult();
        } catch (Exception a){
            a.printStackTrace();
            return new AjaxResult(false,"操作失败");
        }
    }

    @PatchMapping
    @ApiOperation(value = "部门批量删除",notes = "部门批量删除操作")
    public AjaxResult atchDelete(@RequestBody Long[] id){
        try {

                        systemdictionarytypeService.atchDelete(id);

                        systemdictionarytypeService.deletes(id);

            return new AjaxResult();
        } catch (Exception a){
            a.printStackTrace();
            return new AjaxResult(false,"删除失败");
        }
    }
    
}
